using System.Data;
using PCSComUtils.Common;
using PCSComPayroll.DS;

namespace PCSComPayroll.BO
{
	public class BudgetEstimatesBO
	{
		public BudgetEstimatesBO()
		{}
		
		#region IObjectBO Members

		public void UpdateDataSet(System.Data.DataSet dstData)
		{
			// TODO:  Add BudgetEstimatesBO.UpdateDataSet implementation
		}

		public void Update(object pObjectDetail)
		{
			// TODO:  Add BudgetEstimatesBO.Update implementation
		}

		//[AutoComplete(true)]
		public void Delete(object pObjectVO)
		{
			PAY_EstimateMasterVO voMaster = (PAY_EstimateMasterVO)pObjectVO;
			PAY_EstimateMasterDS dsMaster = new PAY_EstimateMasterDS();
			// delete detail
			dsMaster.DeleteDetail(voMaster.EstimateMasterID);
			// delete master
			dsMaster.Delete(voMaster.EstimateMasterID);
		}

		public void Add(object pObjectDetail)
		{
			// TODO:  Add BudgetEstimatesBO.Add implementation
		}

		//[AutoComplete(true)]
		public object GetObjectVO(int pintID, string VOclass)
		{
			PAY_EstimateMasterDS dsMaster = new PAY_EstimateMasterDS();
			return dsMaster.GetObjectVO(pintID);
		}

		#endregion

		//[AutoComplete(true)]
		public DataSet List(int pintMasterID)
		{
			PAY_EstimateDetailDS dsDetail = new PAY_EstimateDetailDS();
			return dsDetail.List(pintMasterID);
		}

		//[AutoComplete(true)]
		public DataSet ListBySale(int pintSaleOrderDetailID)
		{
			PAY_EstimateDetailDS dsDetail = new PAY_EstimateDetailDS();
			return dsDetail.ListBySale(pintSaleOrderDetailID);
		}

		//[AutoComplete(true)]
		public int AddAndReturnID(object pObjectDetail, DataSet pdstData)
		{
			PAY_EstimateMasterDS dsMaster = new PAY_EstimateMasterDS();
			int intNewMasterID = dsMaster.AddAndReturnID(pObjectDetail);
			DataSet dstData = pdstData.Clone();
			foreach (DataRow drowData in pdstData.Tables[0].Rows)
			{
				if (drowData.RowState != DataRowState.Deleted)
				{
					drowData[PAY_EstimateDetailTable.ESTIMATEMASTERID_FLD] = intNewMasterID;
					DataRow drowNew = dstData.Tables[0].NewRow();
					foreach (DataColumn dcolData in pdstData.Tables[0].Columns)
						drowNew[dcolData.ColumnName] = drowData[dcolData.ColumnName];
					dstData.Tables[0].Rows.Add(drowNew);
				}
			}
			PAY_EstimateDetailDS dsDetail = new PAY_EstimateDetailDS();
			dsDetail.UpdateDataSet(dstData);
			return intNewMasterID;
		}

		//[AutoComplete(true)]
		public void Update(object pObjectDetail, DataSet pdstData)
		{
			PAY_EstimateMasterDS dsMaster = new PAY_EstimateMasterDS();
			dsMaster.Update(pObjectDetail);
			if(pdstData != null)
			{
				if(pdstData.Tables.Count > 0)
				{
					PAY_EstimateDetailDS dsDetail = new PAY_EstimateDetailDS();
					dsDetail.UpdateDataSet(pdstData);
				}
			}
		}
		//[AutoComplete(true)]
		public decimal GetPaidPerHour()
		{
			PAY_PayrollParamDS dsParam = new PAY_PayrollParamDS();
			return dsParam.GetPaidPerHour();
		}

		/// <summary>
		/// Check for exist F.Goods Code in master table
		/// </summary>
		/// <param name="pintSaleOrderDetailID">Sale order detail</param>
		/// <returns></returns>
		//[AutoComplete(true)]
		public bool IsExistFGoodsCode(int pintSaleOrderDetailID)
		{
			PAY_EstimateMasterDS dsMaster = new PAY_EstimateMasterDS();
			return dsMaster.IsExistFGoodsCode(pintSaleOrderDetailID);
		}
		/// <summary>
		/// Check for exist ProductionLine in master table
		/// </summary>
		/// <param name="pintSaleOrderDetailID">Estimate Master ID</param>
		/// <param name="pintProductionLineID">Production Line ID</param>
		/// <returns></returns>
		//[AutoComplete(true)]
		public bool IsExistProductionLine(int pintSaleOrderDetailID, int pintProductionLineID)
		{
			PAY_EstimateMasterDS dsMaster = new PAY_EstimateMasterDS();
			return dsMaster.IsExistProductionLine(pintSaleOrderDetailID, pintProductionLineID);
		}
	}
}
